<template>
	<view class="container">
		<view class="logs">
			<view class="cu-list menu-avatar">
				<view class="cu-item arrow" v-for="(item, index) in list" :key="index">
					<view class="cu-avatar round lg" :style="'background-image: url(/static/yuebao.png);'"></view>
					<view class="content">
						<view>累计收益:{{ item.all_interest }}元</view>
						<view>生息天数:{{ item.day }}天</view>
						<view class="text-gray text-xs">
							<view class="text-cut flex margin-top-no">订单号:{{ item.order_id }}</view>
							<view class="text-cut flex margin-top-no">{{ item.create_time }}</view>
							<!-- <view class="text-cut flex margin-top-no">{{ item.note }}</view> -->
						</view>
					</view>
					<view class="action">
						<view class="text-lg coin text-red text-bold">
							{{ item.money }}元
						</view>	
						<view @click="zhuanchu(item)" class="text-white text-sm" v-if="item.status == 0" style="padding: 5px;background: #e54d42;">取出</view>
						<view class="text-gray text-lg" v-else="item.status == 1">已取出</view>
					</view>
				</view>
			</view>
			<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				lastPage: 0,
				list: [],
				loadMoreText: "加载中...",
				showLoadMore: false
			};
		},
		onUnload() {
			this.page = 1,
			this.lastPage = 0,
			this.list = [],
			this.loadMoreText = "加载更多",
			this.showLoadMore = false;
		},
		onLoad: function (option) {
			this.helper.checkLogin();
			this.getData();
		},
		onReachBottom() {
			// console.log("onReachBottom");
			if (this.page > this.lastPage) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}else{
				this.showLoadMore = true;
				setTimeout(() => {
					this.getData();
				}, 300);
			}
		},
		onPullDownRefresh() {
			this.page = 1,
			this.lastPage = 0,
			this.list = [],
			this.loadMoreText = "加载更多",
			this.showLoadMore = false;
			
			setTimeout(() => {
				this.getData();
			}, 300);
		},
		methods: {
			getData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				let page = this.page;
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['token='+info.token,'page='+page,'timestamp='+timestamp]);
				this.helper.req({
					api:"getYebLog",
					timestamp:timestamp,
					data:{token:info.token,page:page},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					let current_page = res.data.data.list.current_page;
					let last_page = res.data.data.list.last_page;
					this.page = current_page + 1;
					this.lastPage = last_page;
					this.list = this.list.concat(res.data.data.list.data);
					if (this.page >= this.lastPage) {
						this.loadMoreText = "没有更多数据了!"
					}
					uni.stopPullDownRefresh();
					uni.hideLoading();
				})
			},
			// 转出
			zhuanchu: function(item) {
				
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['id='+item.id,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"doYuebaoChu", 
					timestamp:timestamp,
					data:{id:item.id,token:info.token},
					header:{sign:sign},
					method:'POST',
				}).then(res=>{
					uni.showModal({
						title: "提示",
						content: '转出成功',
						showCancel:false,
						confirmText: "确认",
						success:function(res){
							if(res.confirm){
								uni.navigateTo({
									url: "/pages/yuebao/index"
								})
							}
						}
					})
				})
				this.coin = "";
			},
			//链接
			toUrl:function(url){
				// console.log(url);
				uni.navigateTo({
					url: url,
				});	
			},
		},
	};
</script>
<style lang="scss">
.cu-list.menu-avatar > .cu-item .action {
    width: 160upx;
}
.cu-avatar{
	background-color: #fff;
}
</style>